import util from '../../common/js/util'
import NProgress from 'nprogress'
import axios from 'axios';
import address from "../../../models/dict/address"
import moment from 'moment'
const dMember = require('../../../models/dict/dMember');
export default {
    data() {
        return {

            currObj: dMember.fmtMember(),
            addressOptions: address.address,
            selectedOptions: []


        }
    },
    methods: {
        getAction() {

            return '/file'

        },

        //显示编辑界面
        getMe: function (index, row) {
            axios.post("/a", {
                class: "member",
                para: "getMe",


            }).then((res) => {
                if (res.data.re == "ok") {

                    this.currObj = dMember.fmtMember(res.data.info);
                    this.ShowSave = true;


                    if (!this.currObj.address) {

                        this.currObj.address = {};
                        this.currObj.address.areaId = '';
                    }

                    if (!this.currObj.class) {

                        this.currObj.class = [];
                    }

                    this.selectedOptions = [this.currObj.address.provinceId, this.currObj.address.cityId, this.currObj.address.areaId]
                }
                else {



                    this.$message.error(res.data.errMsg);
                }

            });

        },
        //保存客户
        saveMember: function () {

            this.currObj.address = address.addressObj(this.selectedOptions, this.currObj.address.memo);
            this.currObj.companyCode = localStorage.companyCode;
            axios.post("/a", {
                class: "member",
                para: "saveMember",
                j: this.currObj

            }).then((res) => {
                if (res.data.re == "ok") {
                    this.ShowSave = false;
                    this.$message({
                        message: '保存成功!',
                        type: 'success'
                    });

                } else {
                    alert(JSON.stringify(res.data));
                }
            });


        },
        picImgUp(a, b) {

            console.dir(a);

            this.currObj.picUrl = a.file.url
            console.log('上传成功!');
        },
        addressChange() {

        }
        //新增





    },


    mounted() {
        this.getMe();
    },

}